import { AxiosInstance } from "axios";
import React from "react";

export type DesignerContextType = {
  axios?: AxiosInstance;
  facilityId?: number;
  // 产品分类编码
  productCodes?: number[];
  children?: React.ReactNode;
};
export const DesignerContext = React.createContext(
  {} as DesignerContextType | undefined
);
export const DesignerProvider = (props: DesignerContextType) => (
  <DesignerContext.Provider value={props}>
    {props.children}
  </DesignerContext.Provider>
);
export const useAxios = () => React.useContext(DesignerContext)?.axios;
export const useFacility = () => React.useContext(DesignerContext)?.facilityId;
export const useProductCodes = () =>
  React.useContext(DesignerContext)?.productCodes;

export type ViewerContextType = {
  pointClick: Function;
  children: React.ReactNode;
};
export const ViewerContext = React.createContext(
  {} as ViewerContextType | undefined
);
export const ViewerProvider = (props: ViewerContextType) => (
  <ViewerContext.Provider value={props}>
    {props.children}
  </ViewerContext.Provider>
);

export const usePointClick = () => React.useContext(ViewerContext)?.pointClick;
